package cn.wolfcode.trip.base.domain;

import cn.wolfcode.trip.base.util.JSONUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Setter
@Getter
public class StrategyDetail extends BaseDomain {

    public static final int STATE_NOMAL=0;//草稿
    public static final int STATE_RELEASE=1;//发布

    private String title;

    private Date createTime;
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date releaseTime;

    private Integer sequence;
    //所属分类
    private StrategyCatalog catalog;

    private String coverUrl;

    private Integer state;

    private StrategyContent strategyContent;

    public String getJson(){
        Map<String,Object> map=new HashMap<>();
        map.put("id", id);
        map.put("title", title);
        map.put("createTime", createTime);
        map.put("releaseTime", releaseTime);
        map.put("sequence", sequence);
        map.put("coverUrl",coverUrl);
        map.put("state",state);
        //当我们封装的是对象的时候,我么你需要判断一下是否存在
        if(catalog!=null){
            map.put("catalogId",catalog.getId());
            map.put("catalogName",catalog.getName());
            if(catalog.getStrategy()!=null){
                map.put("strategyId",catalog.getStrategy().getId());
            }
        }
        return JSONUtil.toJSONString(map);
    }
}